﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Bank
    {
        private string name;   //定义名字
        private double balance; //定义储蓄卡定义余额
        private double arrears;//定义欠款金额
        public string time; //定义还款时间

        public Bank(string name)
        {
            balance = 0;    
            arrears = 5000; 
            this.name = name;
        }

        public void deposit(double amount)
        {
            balance += amount;
        }
        public double Balance
        {
            get { return (double)balance; }
        }
        public double Arrears
        {
            get { return (double)arrears; }
        }

        public void Time(string time)
        {
            this.time = time;
        }
        public void RepayMent()
        {
            balance -= arrears;
            arrears = 0;
            Console.WriteLine("偿还成功！");
            Console.WriteLine("当前余额是{0}元", Balance);
            Console.WriteLine("当前欠款是{0}元", Arrears);
        }

        public void NotRepay()
        {
            Console.WriteLine("还未到还款日，无需还款!");
        }
    }
    class RepayDelegate
    {
        public delegate void RepayM(); //定义委托
        public event RepayM Repay;  //定义事件
        public void RequestRepay()
        {
            if (Repay != null)
            {
                Repay();
            }
        }

    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入你的名字：");
            string name = Console.ReadLine();
            Bank a = new Bank(name);
            Console.WriteLine("请输入储蓄卡剩余金额：");
            double amount = double.Parse(Console.ReadLine());
            a.deposit(amount);

            Console.WriteLine("当前余额是{0}元", a.Balance);
            Console.WriteLine("当前欠款是{0}元", a.Arrears);
            Console.WriteLine("请输入自动还款日：");
            string time = Console.ReadLine();
            a.Time(time);
            RepayDelegate RD = new RepayDelegate();
            if (a.time == ("yyyy-MM-dd").Split('-')[2])
            {

                RD.Repay += new RepayDelegate.RepayM(a.RepayMent);
            }
            else
            {
                RD.Repay += new RepayDelegate.RepayM(a.NotRepay);
            }
            RD.RequestRepay();
            Console.WriteLine("请输入你的大名：");
            name = Console.ReadLine();
            Bank a2 = new Bank(name);
            Console.WriteLine("请输入储蓄卡剩余金额：");
            amount = double.Parse(Console.ReadLine());
            a2.deposit(amount);
            Console.WriteLine("当前余额是{0}元", a2.Balance);
            Console.WriteLine("当前欠款是{0}元", a2.Arrears);
            Console.WriteLine("请输入自动还款日：");
            time = Console.ReadLine();
            a2.Time(time);
            RepayDelegate RD2 = new RepayDelegate();
            if (a2.time == ("yyyy-MM-dd").Split('-')[2])
            {
                RD2.Repay += new RepayDelegate.RepayM(a2.RepayMent);
            }
            else
            {
                RD2.Repay += new RepayDelegate.RepayM(a2.NotRepay);
            }
            RD2.RequestRepay();
        }
    }

}
